<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8" />
  <meta name="author-name" content="Mironcoder | Miron Mahmud" />
  <meta name="author-email" content="mironcoder@gmail.com" />
  <meta name="author-profile" content="https://themeforest.net/user/mironcoder" />
  <meta name="template-name" content="Vegana" />
  <meta name="template-created" content="09-November-2020" />
  <meta name="template-title" content="Vegana - vegan food eCommerce store html template" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
  <meta name="keywords" content="vegana, vegan, food, eCommerce, store, html, template, bootstrap, vegetarian, organic, vegetables, greengrocery, fruit, healthy, shop" />
  <title>右侧边栏购物</title>
  <link rel="icon" href="../assets/images/logo/favicon.png" />
  <link rel="stylesheet" href="../assets/source/css/vendor/flaticon.css" />
  <link rel="stylesheet" href="../assets/source/css/vendor/fontawesome.css" />
  <link rel="stylesheet" href="../assets/source/css/vendor/jquery-ui.css" />
  <link rel="stylesheet" href="../assets/source/css/vendor/bootstrap.min.css" />
  <link rel="stylesheet" href="../assets/source/css/custom/main.css" />
  <link rel="stylesheet" href="../assets/source/css/custom/shop-rightbar.css" />
  <link rel="stylesheet" href="../back/css/index.css">
 </head>
 <body>
  <div id="app"> 
  <header class="header-part">
   <div class="container">
    <div class="row">
     <div class="col-sm-12 col-md-6 col-lg-6">
      <ul class="header-info">
        <li> <i class="fas fa-envelope"></i><p>{{adminEmail}}</p></li>
        <li> <i class="fas fa-phone-alt"></i><p>+{{adminTel}}</p></li>
      </ul>
     </div>
     <div class="col-sm-12 col-md-6 col-lg-6">
      <div class="login_info" v-if="userInfo == ''">
				<a href="login.html" target="_blank" title="点击登录">您好，请先登录</a>
				<a href="reg.html" target="_blank" title="点击注册">免费注册</a>
			</div>
			<div class="login_info" v-else>
				<span>尊敬的用户{{userInfo.uname}},您好</span>
				<a href="login.html" title="点击退出">退出登录</a>
			</div>
     </div>
    </div>
   </div> 
  </header> 
  <nav class="navbar-part">
   <div class="container">
    <div class="row">
     <div class="col-lg-12">
      <div class="navbar-element">
       <ul class="left-widget">
        <li><a class="icon icon-inline menu-bar" href="#"><i class="fas fa-align-left"></i></a></li>
       </ul> 
       <a class="navbar-logo" href="#"> <img src="../assets/images/logo/01.png" alt="logo" /> </a>
       <div class="search-form navbar-src"> 
        <input type="text" placeholder="商品名..." v-model="pname"/> 
        <button class="btn btn-inline" @click="search"> <i class="fas fa-search"></i> <span>搜索</span> </button>
       </div>
       <ul class="right-widget">
        <li><a class="icon icon-inline" href="login.html"><i class="fas fa-user"></i></a></li>
        <li><a class="icon icon-inline" href="wishlist.html"><i class="fas fa-heart"></i><sup>{{wishCount}}</sup></a></li>
        <li><a class="icon icon-inline" href="cartlist.html"><i class="fas fa-shopping-cart"></i><sup>{{cartCount}}</sup></a></li>
       </ul>
      </div>
     </div>
    </div>
    <div class="row">
     <div class="col-lg-12">
      <div class="navbar-slide">
       <div class="navbar-content">
        <div class="navbar-slide-cross"> 
         <a class="icon icon-inline cross-btn" href="#"><i class="fas fa-times"></i></a>
        </div>
        <div class="navbar-slide-logo"> 
         <a href="#"><img src="../assets/images/logo/01.png" alt="logo" /></a>
        </div>
        <form class="search-form mb-4 navbar-slide-src"> 
         <input type="text" placeholder="Search anything..." /> 
         <button class="btn btn-inline"> <i class="fas fa-search"></i> <span>搜索</span> </button>
        </form>
        <ul class="navbar-list">
         <li class="navbar-item active"><a class="navbar-link" href="../index.html">家</a></li>
         
         <li class="navbar-item navbar-dropdown"> <a class="navbar-link dropdown-indicator" href="#"> <span>店</span> <i class="fas fa-chevron-down"></i> </a>
          <ul class="dropdown-list">
           <li><a class="dropdown-link" href="shop-rightbar.html">使用右栏购物</a></li>
          </ul></li>
         <li class="navbar-item navbar-dropdown"> <a class="navbar-link dropdown-indicator" href="#"> <span>页面</span> <i class="fas fa-chevron-down"></i> </a>
          <ul class="dropdown-list">
           <li><a class="dropdown-link" href="cartlist.html">购物清单</a></li>
           <li><a class="dropdown-link" href="wishlist.html">心愿单</a></li>
           
           <li><a class="dropdown-link" href="login.html">注销</a></li>
          </ul></li>
         <li class="navbar-item navbar-dropdown"> <a class="navbar-link dropdown-indicator" href="#"> <span>博客</span> <i class="fas fa-chevron-down"></i> </a>
          <ul class="dropdown-list">
           <li><a class="dropdown-link" href="blog-list.html">博客列表</a></li>
          </ul></li>
         <li class="navbar-item"><a class="navbar-link" href="account.html">账户</a></li>
         <li class="navbar-item"><a class="navbar-link" href="contact.html">联系</a></li>
        </ul>
       </div>
      </div>
     </div>
    </div>
   </div> 
  </nav>
  <div class="btmbar-part">
   <ul class="btmbar-widget">
    <li> <a href="../index.html"> <i class="fas fa-home"></i> <span>Home</span> </a></li>
    <li> <a href="wishlist.html" class="wish-icon"> <i class="fas fa-heart"></i> <span>Wishlist</span> <sup>0</sup> </a></li>
    <li> <a href="cartlist.html" class="cart-icon"> <i class="fas fa-shopping-basket"></i> <span>Cart</span> <sup>0</sup> </a></li>
    <li> <a href="account.html"> <i class="fas fa-cog"></i> <span>Settings</span> </a></li>
   </ul>
  </div> 
  <section class="single-banner">
   <div class="container">
    <div class="row">
     <div class="col-lg-12">
      <div class="single-content">
       <h2>Shop with right sidebar</h2>
       <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="../home-1.html">Home</a></li>
        <li class="breadcrumb-item active" aria-current="page">Shop</li>
       </ol>
      </div>
     </div>
    </div>
   </div> 
  </section> 
  <section class="product-list">
   <div class="container">
    <div class="row">
     <div class="col-lg-9">
      <div class="row">
       <div class="col-lg-12">
        <div class="product-filter">
         <div class="product-page-number">
          <p>显示1–{{pageSize}}个结果 (共{{productNum}}个结果)</p>
         </div> 
         <select class="product-short-select custom-select"><option selected="">Short by Best Sell</option><option value="1">Short by New Item</option><option value="2">Short by Popularity</option><option value="3">Short by Average review</option> </select>
         <ul class="product-card-type">
          <li class="grid-verti active"><i class="fas fa-grip-vertical"></i></li>
          <li class="grid-hori"><i class="fas fa-grip-horizontal"></i></li>
         </ul>
        </div>
       </div>
      </div>
      <div class="row product-card-parent">
        <!--商品-->
       <div v-for="item in product" class="col-6 col-sm-6 col-md-4 col-lg-4">
        <div class="product-card card-gape">
         <div class="product-img"> 
          <img :src=`../../upload/${item.pic}` alt="product-12" />
          <ul class="product-widget">
           <li><button><i class="fas fa-eye"></i></button></li>
           <li><button @click="addWish(item)"><i class="fas fa-heart"></i></button></li>
          </ul>
         </div>
         <div class="product-content">
          <div class="product-name">
           <h6><a :href=`product-details.html?${item.pid}`>{{item.pname}}</a></h6>
          </div>
          <div class="product-price">
           <h6>
            <del>
             ${{((item.outprice*0.2)+parseFloat(item.outprice)).toFixed(2)}}
            </del> ${{item.outprice}}</h6>
           <div class="product-rating"> 
            <i class="fas fa-star"></i> 
            <span>{{item.pf == null ? 0 : parseFloat(item.pf).toFixed(1)}}/{{item.count}}</span>
           </div>
          </div>
          <div class="product-btn"> 
          <a href="#" @click="addCart(item)"> <i class="fas fa-shopping-basket"></i> <span>添加购物车</span> </a>
          </div>
         </div>
        </div>
       </div>
      </div>


      <div class="row">
       <div class="col-lg-12">
        <ul class="pagination">
          <!--
         <li class="page-item"> <a class="page-link" href="javascript:void(0)" @click="getGoodsByPage(1)"> 首页 </a></li>
         <li><a href="javascript:void(0)" @click="getGoodsByPage(n)" :class="n == page ? 'page-link active' : ''" v-for="n in pages">{{n}}</a></li>
         <li class="page-item"> <a class="page-link" href="javascript:void(0)" @click="getGoodsByPage(pages)"> 尾页</a></li>
        -->
        <el-pagination
        layout="prev, pager, next"
        :total="productNum"
        :page-size="pageSize"
        :current-page="page"
        @current-change="getGoodsByPage">
  		  </el-pagination>
        </ul>
       </div>
      </div>
     </div>
     <div class="col-lg-3">
      <div class="product-ad"> 
       <a href="javascript:void(0)"><img src="../assets/images/ad-banner/01.jpg" alt="ad" /></a>
      </div>
      <div class="product-bar">
       <h6>Filter by Price</h6> 
       <input type="text" id="amount" readonly="" />
       <div id="slider-range"></div>
      </div>
      <!--
      <div class="product-bar">
       <h6>按标签筛选</h6>
       <div class="product-bar-content"> 
        <ul class="scroll-list">
         <li>
          <div class="custom-control custom-checkbox"> 
           <input type="checkbox" class="custom-control-input" id="check8" /> 
           <label class="custom-control-label" for="check8">Alcohol-Free</label>
          </div> <span class="product-cate-number">(13)</span></li>
        </ul> 
        <button class="clear-filter-btn"> <i class="fas fa-broom"></i> <span>过滤器清除</span> </button>
       </div>
      </div>
      -->

      <div class="product-bar">
        <h6>按类别筛选</h6>
        <div class="product-bar-content"> 
         <ul class="scroll-list">
          <li v-for="(item,index) in types">
           <div class="custom-control custom-checkbox"> 
            <input type="checkbox" class="custom-control-input" v-model="item.checked" :id="`check${index}`" /> 
            <label class="custom-control-label" :for="`check${index}`">{{item.tname}}</label>
           </div> <span class="product-cate-number">({{item.count}})</span></li>
         </ul> 
        </div>
       </div>
      
     </div>
    </div>
   </div> 
  </section> 
  <section class="news-part">
   <div class="container">
    <div class="row">
     <div class="col-md-5 col-lg-6">
      <div class="news-content">
       <h2>Subscribe for Latest Offers</h2>
      </div>
     </div>
     <div class="col-md-7 col-lg-6">
      <form class="search-form news-form"> 
       <input type="text" placeholder="Enter Email Address" /> 
       <button class="btn btn-inline"> <i class="fas fa-envelope"></i> <span>Subscribe</span> </button>
      </form>
     </div>
    </div>
   </div> 
  </section> 
  <footer class="footer-part">
   <div class="container">
    <div class="row">
     <div class="col-md-6 col-lg-4">
      <div class="footer-content"> 
       <a href="#"><img src="../assets/images/logo/01.png" alt="logo" /></a>
       <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequatur repudiandae quisquam adipisci asperiores, ipsum ipsa repellat assumenda dolor perspiciatis.</p>
       <ul class="footer-icon">
        <li><a class="icon icon-inline" href="#"><i class="fab fa-facebook-f"></i></a></li>
        <li><a class="icon icon-inline" href="#"><i class="fab fa-twitter"></i></a></li>
        <li><a class="icon icon-inline" href="#"><i class="fab fa-linkedin-in"></i></a></li>
        <li><a class="icon icon-inline" href="#"><i class="fab fa-instagram"></i></a></li>
        <li><a class="icon icon-inline" href="#"><i class="fab fa-pinterest-p"></i></a></li>
       </ul>
      </div>
     </div>
     <div class="col-md-6 col-lg-4">
      <div class="footer-content">
       <h3 class="title">Useful Links</h3>
       <div class="footer-widget">
        <ul>
         <li><a href="#">My Account</a></li>
         <li><a href="#">Order History</a></li>
         <li><a href="#">Order Tracking</a></li>
         <li><a href="#">Best Seller</a></li>
         <li><a href="#">New Arrivals</a></li>
        </ul>
        <ul>
         <li><a href="#">Location</a></li>
         <li><a href="#">Affiliates</a></li>
         <li><a href="#">Contact</a></li>
         <li><a href="#">Carrer</a></li>
         <li><a href="#">Faq</a></li>
        </ul>
       </div>
      </div>
     </div>
     <div class="col-md-12 col-lg-4">
      <div class="footer-content">
       <h3 class="title">Download the App</h3>
       <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit dicta amet tenetur soluta blanditiis at optio molestias facilis praesentium eos! Sed placeat a labore corporis aliquam reiciendis eaque quisquam corrupti.</p>
      </div>
      <ul class="download-app">
       <li><a href="#"><img src="../assets/images/logo/google.png" alt="google" /></a></li>
       <li><a href="#"><img src="../assets/images/logo/app.png" alt="app" /></a></li>
      </ul>
     </div>
    </div>
   </div> 
  </footer>
  <div class="footer-bottom">
   <div class="container">
    <p>Copyright &copy; 2020 | All rights reserved by <a target="_blank" href="https://themeforest.net/user/mironcoder">Mironcoder</a></p>
    <ul class="pay-card">
     <li><a href="#"><img src="../assets/images/pay-card/01.jpg" alt="payment-1" /></a></li>
     <li><a href="#"><img src="../assets/images/pay-card/02.jpg" alt="payment-2" /></a></li>
     <li><a href="#"><img src="../assets/images/pay-card/03.jpg" alt="payment-3" /></a></li>
     <li><a href="#"><img src="../assets/images/pay-card/04.jpg" alt="payment-4" /></a></li>
    </ul>
   </div>
  </div>
  </div>
  <script src="../js/vue.js"></script>
  <script src="../js/axios.js"></script>
  <script src="../js/qs.js"></script> 
  <script src="../assets/source/js/vendor/jquery-1.12.4.min.js"></script> 
  <script src="../assets/source/js/vendor/popper.min.js"></script> 
  <script src="../assets/source/js/vendor/bootstrap.min.js"></script> 
  <script src="../assets/source/js/vendor/jquery-ui.js"></script> 
  <script src="../assets/source/js/custom/main.js"></script>
  <script src="../back/js/index.js"></script>
  <script>
    let max = 0;
    let min = 0;
    $(function(){
    $("#slider-range").slider({
        range:true,min:0,max:500,values:[0,500],
        slide:function(event,ui){
            //console.log("Slider value changed to: " + ui.value);
            $("#amount").val("$"+ui.values[0]+" - $"+ui.values[1]);
            min = ui.values[0];
            max = ui.values[1];
        }});
        $("#amount").val("$"+$("#slider-range").slider("values",0)+" - $"+$("#slider-range").slider("values",1));
        
    });
    let app = new Vue({
       el:'#app',
       data:{
          adminEmail:'',
          adminTel:'',
          uid:'',
          userInfo:{},//用户信息
          types:[],//类别信息
          cartCount:0,//购物车数量
          wishCount:0,//心愿单数量///
          product:[],//商品
          pname:'',//商品名
          page:1,//当前页码
			    pageSize:3,
          pages:0,
          min:'',
			    max:'',
          productNum:0,//商品数量
          typeId:[],//存选中的类别id
          tid:'',
       },
       methods:{
          findAdminInfo(){//查询管理员信息
            axios.get("../userController/findAdminInfo").then(resp=>{
              localStorage.setItem("adminEmail",resp.data.email);
              localStorage.setItem("adminTel",resp.data.tel);
              this.adminEmail = resp.data.email;
              this.adminTel = resp.data.tel;
              
            });
          },
          findUserInfo(){//查询用户信息
            let uid = localStorage.getItem("uid");
              if(uid == null || uid == ""){
                alert("请先登录");
                  location.href="login.html";
					        return;
                
				    }else{
              this.uid = localStorage.getItem("uid");
            }
            axios.get("../userController/findUserInfo").then(resp=>{
                if(resp.data == -1){
                  alert("请先登录");
                  location.href = "login.html";
                  return;
                }else{
                  this.userInfo = resp.data;
                  console.log(resp.data);
                }
              });  
          },
          findTypes(){
            axios.get("../typeController/findTypes").then(resp=>{
              this.types = resp.data;
            });
          },
          getCartCount(){//得到购物车数量
            if(this.userInfo == null){
              return;
            }
            let count = localStorage.getItem("cartCount");
            if(count == null || count == ""){
              axios.get("../carInfoController/getCartCount",{
                params:{
                  uid:this.uid
                }
                }).then(resp=>{
                this.cartCount = resp.data;
                console.log(this.cartCount);
                //存值
                localStorage.setItem("cartCount",this.cartCount);
              });
            }else{
              this.cartCount = count;
            }		
			    },
          getWishCount(){//得到心愿单数量
            if(this.userInfo == null){
              return;
            }
            let count = localStorage.getItem("wishCount");
            if(count == null || count == ""){
              axios.get("../wishController/getWishCount",{
                params:{
                  uid:this.uid
                }
                }).then(resp=>{
                this.wishCount = resp.data;
                //存值
                localStorage.setItem("wishCount",this.wishCount);
              });
            }else{
              this.wishCount = count;
            }		
			    },
          getProduct(){//查出商品
            if(this.userInfo == null){
              return;
            }
            this.productNum = 0;
            this.tid = this.typeId.join(",");
            axios.get("../productController/getProduct",{
              params:{
						      page:this.page,
                  pageSize:this.pageSize,
                  min:this.min,
                  max:this.max,
                  pname:this.pname,
                  tid:this.tid					
					    }
            }).then(resp=>{
              this.product = resp.data;
              console.log(this.product);
              this.pages = Math.ceil(resp.data[0].productcount/this.pageSize);
              this.productNum = Number(resp.data[0].productcount);
            });
          },
          getGoodsByPage(currentPage){
            this.page = currentPage;
           
            this.tid = this.typeId.join(",");
              axios.get("../productController/getGoodsByPage",{
                params:{
                  page:this.page,
                  pageSize:this.pageSize,
                  min:this.min,
                  max:this.max,
                  pname:this.pname,
                  tid:this.tid
                }
              }).then(resp=>{
                this.product = resp.data;
              });
          },
          search(){
            this.typeId = [];
            this.productNum = 0;
            this.page = 1;//新的搜索，默认显示第一页
            this.min = min;
            this.max = max;
            this.types.forEach(item=>{
                    if(item.checked){
                        this.typeId.push(item.tid);
                    }
            });
            this.tid = this.typeId.join(",");
            axios.get("../productController/getProduct",{
              params:{
						      page:this.page,
                  pageSize:this.pageSize,
                  min:this.min,
                  max:this.max,
                  pname:this.pname,
                  tid:this.tid					
					    }
            }).then(resp=>{
              this.product = resp.data;
              if(resp.data == ''){
                this.pages = Math.ceil(0/this.pageSize);
                this.productNum = 0;
              }else{
                this.pages = Math.ceil(resp.data[0].productcount/this.pageSize);
                this.productNum = Number(resp.data[0].productcount);
              }
            });
          },
          addWish(obj){
            axios.get("../wishController/addWish",{
              params:{
                uid:this.uid,
                pid:obj.pid,
                price:obj.outprice,
                num:1,
                inventory:obj.inventory
              }
            }).then(resp=>{
                if(resp.data != -1 && resp.data != 3){
                  alert("添加心愿单成功");
                  //重新存值
                  if(resp.data == 2){
                    localStorage.setItem("wishCount",parseInt(this.wishCount) + 1);
                  }
                  this.getWishCount();
                }else if(resp.data == 3){
                    alert("库存不足");
                    return;
                }else{
                  alert("添加心愿单失败");
                  return;
                }
            });
          },
          addCart(obj){
            axios.get("../carInfoController/addCart",{
              params:{
                uid:this.uid,
                pid:obj.pid,
                num:1,
                inventory:obj.inventory
              }
            }).then(resp=>{
                if(resp.data != -1 && resp.data != 3){
                  alert("添加购物车成功");
                  //重新存值
                  if(resp.data == 2){
                    localStorage.setItem("cartCount",parseInt(this.cartCount) + 1);
                  }
                  this.getCartCount();
                }else if(resp.data == 3){
                    alert("库存不足");
                    return;
                }else{
                  alert("添加购物车失败");
                  return;
                }
            });
          }
       },
       mounted(){
          this.getProduct();
       },
       created(){
          this.findAdminInfo();
          this.findUserInfo();
          this.findTypes();
          this.getCartCount();
          this.getWishCount();
          
       }
   });
  </script> 
 </body>
</html>